<?php
/**
 *
 *
 *
 */
abstract class Yz_Form_Element_Abstract
    extends Yz_Object
    implements Yz_Form_Element_Interface
{

    protected $form;
    protected $name;
    protected $cssClass;
    protected $isParseable = false;
    protected $error;


    /**
     *  @return name/title
     */
    final public function __toString()
    {
        return strtr($this->_class_(), '\\_', '..') . '.' . $this->name;
    }


    /**
     *  Getter: x = $element->name
     *
     */
    final public function getName()
    {
        return $this->name;
    }

    /**
     *  Getter: x = $element->cssClass
     *
     */
    public function getCSSClass()
    {
        $css = 'yz-form-element yz-form-element-' . $this->_name_();
        if ($this->cssClass)
            $css .= ' ' . $this->cssClass;
        if ($this->error)
            $css .= ' yz-error';
        return $css;
    }

    /** Whether element is parseable
     *
     */
    final public function isParseable()
    {
        return $this->isParseable;
    }

    /**
     *  @return bool(true)
     */
    public function allowEmpty()
    {
        debug();
        return true;
    }

    /** @abstract
     *
     */
    // public function render(Yz_Template_Interface $template)

    /** 'parse' form-data array values to obtain correct value
     *      return boolean, whether the value is to be assigned
     *  @param mixed $value
     *  @return bool
     *  @throw ?
     *  @abstract
     */
    // public function parse($input)

    /**
     *  Getter: x = $element->errorCode
     *
     */
    final public function getError()
    {
        return $this->error;
    }


    /**
     *  Getter: x = $element->value
     *  @return string|null
     */
    public function getValue()
    {
        return $this->value;
    }

    /**
     *  Setter: $element->value = x
     *  Value can be of various types but it must be convertible to string
     *  @param mixed $value
     *
     */
    public function setValue($value)
    {
        $this->value = $value;
        return $this;
    }


}
